﻿
@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}


    <div class="ibox">
        <div class="ibox-content">
            <div id="toolbar" class="btn-group">

            </div>
            <table id="table"></table>
        </div>
    </div>

@section scripts{
    <script>
        $(function () {
            loadGrid();
        });

        function loadGrid() {
            $table = $("#table").bootstrapTable({
                url: '/work/addressbook/GetData',
                toolbar: '#toolbar',
                pagination: true,
                method: 'get',
                height: $(window).height() - 50,
                pageSize: 15,
                pageList: [5, 10, 15, 20],
                showColumns: true,
                showRefresh: true,
                clickToSelect: true,
                sidePagination: "server",
                locale: "zh-CN",
                striped: true,
                queryParams: function (params) {
                    var params2 = {

                        limit: params.limit, //每页多少条
                        offset: params.offset, //从第几条开始读(默认就好)
                        //ntitle: $("#ntitle").val(),
                    };
                    return params2;
                },
                columns: [
                    { field: 'ck', checkbox: true },
                    { field: 'real_name', title: '姓名', align: 'center' },
                    { field: 'work_job', title: '职务', align: 'center' },
                    {
                        field: 'inner_tel', title: '办公电话', align: 'left'
                    },
                    { field: 'mobile', title: '手机号码', align: 'center' },
                    { field: 'department_name', title: '部门', align: 'center' },
                    { field: 'sort_num', title: '排序', align: 'center' },
                    {
                        field: 'id', title: '操作', align: 'center',
                        formatter: renderOperation
                    }
                ]

            });

            jutils.initToolBarRole('#toolbar');
        }

        function renderOperation(v, r, i) {
            var html = jutils.initToolBarRow(v);
            return html;
        }

        function add() {
            location.href = '/work/addressbook/form?id=0';
        }

        function edit(obj) {
            var id = $(obj).data('id');
            location.href = '/work/addressbook/form?id=' + id;
        }

        function del(obj) {
            var id = $(obj).data('id');
            jutils.confirm('确认删除吗',
                function () {
                    jutils.ajaxGet('/work/addressbook/DeleteByIds',
                        { ids: id },
                        function () {
                            $table.bootstrapTable('refresh');
                        });
                });
        }

        function viewDetail(obj) {
            var id = $(obj).data('id');
            location.href = '/work/addressbook/detail?id=' + id;
        }


        function batchDel() {
            var rows = $table.bootstrapTable('getSelections');
            if (rows.length === 0) {
                jutils.alert("请选择需要删除的数据行");
            }
            var ids = [];
            for (var i = 0; i < rows.length; i++) {
                ids.push(rows[i].id);
            }
            jutils.confirm('确认删除吗',
                function () {
                    jutils.ajaxGet('/work/addressbook/DeleteByIds',
                        { ids: ids.join() },
                        function () {
                            $table.bootstrapTable('refresh');
                        });
                });
        }


    </script>
}



